<?php

namespace app\common\model;

use think\Db;


class Contacts {

    public function getAllUserContacts($uid){
        $sql = 'select tid,name,tel,msg,email,addr from contacts where  uid = :uid ORDER BY ttime desc';
        return Db::query($sql,['uid'=>$uid]);
    }

    public function getContactsById($tid){
        $sql = 'select c.*,u.username from contacts c LEFT JOIN user u on u.uid = c.uid where c.tid = :tid';
        return Db::query($sql,['tid'=>$tid]);
    }


    public function add($uid, $name, $tel, $msg, $email, $addr){
        $sql = 'insert into contacts (uid,name,tel,email,addr,msg) VALUE (:uid, :name, :tel, :email, :addr, :msg) ';
        return Db::query($sql,['uid'=>$uid,'name'=>$name,'tel'=>$tel,'msg'=>$msg,'email'=>$email,'addr'=>$addr]);
    }

    public function edit($tid, $name, $tel, $msg, $email, $addr){
        $sql = "update contacts set name = :name, tel = :tel, email = :email, addr = :addr, msg = :msg where tid = :tid";

        return Db::query($sql,['tid'=>$tid,'name'=>$name,'tel'=>$tel,'msg'=>$msg,'email'=>$email,'addr'=>$addr]);
    }

    public function deleteContacts($tid){
        $sql = "delete from contacts where tid = :tid";

        return Db::query($sql,['tid'=>$tid]);
    }




}